﻿@model QuanLyHocSinh.Models.NhapHocSinhModel

@{
    ViewBag.Title = "Tao Hoc Sinh";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Nhập học sinh</h2>

@using (Html.BeginForm("TaoHocSinh", "HocSinh", FormMethod.Post, new { @class = "form_bg", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Hoc Sinh</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="form-group">
            @Html.LabelFor(model => model.MaSV, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.TextBoxFor(model => model.MaSV, new { @class = "form-control", required = "" })
                @Html.ValidationMessageFor(model => model.MaSV, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.TenSV, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.TextBoxFor(model => model.TenSV, new { @class = "form-control", required = "" })
                @Html.ValidationMessageFor(model => model.TenSV, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.NgaySinh, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                <input class="form-control datepicker" id="NgaySinh" name="NgaySinh" type="text" required="" data-val="true" value="" data-val-required="Chọn ngày sinh">
                @Html.ValidationMessageFor(model => model.NgaySinh, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.KhoaHoc, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.DropDownListFor(model => model.KhoaHoc, (List<SelectListItem>)ViewBag.KhoaHoc, "--", new { @class = "form-control", required = "" })
                @Html.ValidationMessageFor(model => model.KhoaHoc, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.GioiTinh, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.DropDownListFor(model => model.GioiTinh, (List<SelectListItem>)ViewBag.GioiTinh, new { @class = "form-control", required = "" })
                @Html.ValidationMessageFor(model => model.GioiTinh, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Lop, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.DropDownListFor(model => model.Lop, (List<SelectListItem>)ViewBag.DsLop, "--", new { @class = "form-control", required = "" })
                @Html.ValidationMessageFor(model => model.Lop, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Nganh, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.TextBoxFor(model => model.Nganh, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Nganh, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.AnhChanDung, new { @class = "control-label col-md-2" })
            <div class="col-md-4 col-xs-12">
                @Html.TextBoxFor(m => m.FileAnhUpload,
               new
               {
                   @class = "btn btn-default",
                   type = "file",
                   required = "",
                   title = "Mở file hoặc kéo thả vào đây",
                   data_val = "true",
                   data_val_required = "Mở một file ảnh hoặc kéo thả vào đây."
               })
                @Html.ValidationMessageFor(model => model.FileAnhUpload, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-4 col-xs-12">
                <input type="submit" value="Tạo" class="btn btn-primary" />
            </div>
            <div class="col-md-12 message" style="text-align: center; color: red;">@ViewBag.ThongBao</div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Quay lại danh sách", "DanhSach")
</div>
<script>
    $(document).ready(function () {
        $('#FileAnhUpload').val('').on("change", CheckFileName);
    });

    var CheckFileName = function () {
        var filename = $('#FileAnhUpload').val();
        var fileext = filename.substring(filename.lastIndexOf('.'), filename.length).toLowerCase();
        console.log(fileext);
        // Check file extenstion
        if (fileext != ".jpg" && fileext != ".jpeg") {
            alert("Chỉ cho phép file ảnh .jpg hoặc .jpeg");
            $('#FileAnhUpload').focus().val('');
            return false;
        }

        return true;
    }
</script>